﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;

namespace CommunitySystemModel
{
    public class PeiXunModel
    {
        private int _Sec;
        [DataMember]
        public int Sec
        {
            get { return _Sec; }
            set { _Sec = value; }
        }
        private int _ID;
        [DataMember]
        public int ID
        {
            get { return _ID; }
            set { _ID = value; }
        }

        private int _PiaoShu;
        [DataMember]
        public int PiaoShu
        {
            get { return _PiaoShu; }
            set { _PiaoShu = value; }
        }

        private int _YuPiao;
        [DataMember]
        public int YuPiao
        {
            get { return _YuPiao; }
            set { _YuPiao = value; }
        }
        private int _XianZhiPiaoShu;
        [DataMember]
        public int XianZhiPiaoShu
        {
            get { return _XianZhiPiaoShu; }
            set { _XianZhiPiaoShu = value; }
        }
        /// <summary>
        /// 0为未结束，1为已结束，2为余票不足
        /// </summary>
        private int _Status;
        [DataMember]
        public int Status
        {
            get { return _Status; }
            set { _Status = value; }
        }

        private string _StatusString;
        [DataMember]
        public string StatusString
        {
            get { return _StatusString; }
            set { _StatusString = value; }
        }

        private string _Name;
        [DataMember]
        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        private string _JiangZuoType;
        [DataMember]
        public string JiangZuoType
        {
            get { return _JiangZuoType; }
            set { _JiangZuoType = value; }
        }

        private string _ZhuJiangRen;
        [DataMember]
        public string ZhuJiangRen
        {
            get { return _ZhuJiangRen; }
            set { _ZhuJiangRen = value; }
        }

        private string _JiangZuoShiJijan;
        [DataMember]
        public string JiangZuoShiJijan
        {
            get { return _JiangZuoShiJijan; }
            set { _JiangZuoShiJijan = value; }
        }

        private string _JiangZuoDiDian;
        [DataMember]
        public string JiangZuoDiDian
        {
            get { return _JiangZuoDiDian; }
            set { _JiangZuoDiDian = value; }
        }

        private DateTime? _StartTime;
        [DataMember]
        public DateTime? StartTime
        {
            get { return _StartTime; }
            set { _StartTime = value; }
        }

        private DateTime? _EndTime;
        [DataMember]
        public DateTime? EndTime
        {
            get { return _EndTime; }
            set { _EndTime = value; }
        }

        public static PeiXunModel FillEntity(DataRow dr)
        {
            PeiXunModel right = new PeiXunModel();
            if (dr.Table != null && dr.Table.Columns.Contains("Sec")) if (!string.IsNullOrEmpty(dr["Sec"].ToString())) right.Sec = Convert.ToInt32(dr["Sec"]);
            if (dr.Table != null && dr.Table.Columns.Contains("ID")) if (!string.IsNullOrEmpty(dr["ID"].ToString())) right.ID = Convert.ToInt32(dr["ID"]);
            if (dr.Table != null && dr.Table.Columns.Contains("PiaoShu")) if (!string.IsNullOrEmpty(dr["PiaoShu"].ToString())) right.PiaoShu = Convert.ToInt32(dr["PiaoShu"]);
            if (dr.Table != null && dr.Table.Columns.Contains("XianZhiPiaoShu")) if (!string.IsNullOrEmpty(dr["XianZhiPiaoShu"].ToString())) right.XianZhiPiaoShu = Convert.ToInt32(dr["XianZhiPiaoShu"]);
            if (dr.Table != null && dr.Table.Columns.Contains("YuPiao")) if (!string.IsNullOrEmpty(dr["YuPiao"].ToString())) right.YuPiao = Convert.ToInt32(dr["YuPiao"]);
            if (dr.Table != null && dr.Table.Columns.Contains("Status")) if (!string.IsNullOrEmpty(dr["Status"].ToString()))
            {
                right.Status = Convert.ToInt32(dr["Status"]);
                if (right.Status == 0) right.StatusString = "可订票";
                if (right.Status == 1) right.StatusString = "已结束";
                if (right.Status == 0 && right.YuPiao <= 5) right.StatusString = "余票不多";
                if (right.YuPiao <= 0) right.StatusString = "已结束";
            }
            if (dr.Table != null && dr.Table.Columns.Contains("StartTime")) if (!string.IsNullOrEmpty(dr["StartTime"].ToString())) right.StartTime = Convert.ToDateTime(dr["StartTime"]);
            if (dr.Table != null && dr.Table.Columns.Contains("EndTime")) if (!string.IsNullOrEmpty(dr["EndTime"].ToString())) right.EndTime = Convert.ToDateTime(dr["EndTime"]);

            if (dr.Table != null && dr.Table.Columns.Contains("Name")) if (!string.IsNullOrEmpty(dr["Name"].ToString())) right.Name = dr["Name"].ToString();
            if (dr.Table != null && dr.Table.Columns.Contains("JiangZuoType")) if (!string.IsNullOrEmpty(dr["JiangZuoType"].ToString())) right.JiangZuoType = dr["JiangZuoType"].ToString();
            if (dr.Table != null && dr.Table.Columns.Contains("ZhuJiangRen")) if (!string.IsNullOrEmpty(dr["ZhuJiangRen"].ToString())) right.ZhuJiangRen = dr["ZhuJiangRen"].ToString();
            if (dr.Table != null && dr.Table.Columns.Contains("JiangZuoShiJijan")) if (!string.IsNullOrEmpty(dr["JiangZuoShiJijan"].ToString())) right.JiangZuoShiJijan = dr["JiangZuoShiJijan"].ToString();
            if (dr.Table != null && dr.Table.Columns.Contains("JiangZuoDiDian")) if (!string.IsNullOrEmpty(dr["JiangZuoDiDian"].ToString())) right.JiangZuoDiDian = dr["JiangZuoDiDian"].ToString();
            return right;
        }
    }


}
